const tree_main = document.querySelector('#tree_main')

function shujiegou(data) {
    const newData = []
    data.forEach((item) => {
        if (item.pid === '') {
            item.children = []
            const id = item.id

            data.forEach((childrenItem) => {
                if (childrenItem.pid === id) {
                    item.children.push(childrenItem)
                }

                function nn() {
                    const dd = item.childrenItem.huan
                    dd = []
                    childrenItem.forEach((item1) => {
                        if (item1 !== '') {
                            dd.push(item1)
                        }
                        console.log(dd);
                    })
                    nn()
                }

            })

            newData.push(item)

        }




    })
    return tree_main.innerHTML = newData
}
const arr = shujiegou(depts)
console.log(arr);